﻿<fluent:MetroWindow x:Class="OpenPresenter.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:fluent="clr-namespace:Fluent;assembly=Fluent"
        xmlns:slidetypes="clr-namespace:OpenPowerPoint.Slides;assembly=OpenPowerPoint"
        xmlns:elements="clr-namespace:OpenPowerPoint.Slides.Elements;assembly=OpenPowerPoint"
        xmlns:local="clr-namespace:OpenPresenter"
        xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
        Name="window" WindowState="Maximized"
        Title="OpenPresenter ~ Alpha ~" Height="768" Width="1024" Loaded="RibbonWindow_Loaded" RibbonThemeColor="DarkOrange">

    <fluent:MetroWindow.Resources>
        <DataTemplate DataType="{x:Type elements:Shape}" x:Key="ShapeTemplate" >
            <Grid>
                <Grid.RenderTransform>
                    <RotateTransform Angle="{Binding Path=Rotation}"/>
                </Grid.RenderTransform>
                
                <FlowDocumentScrollViewer Document="{Binding Path=Content}" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden"/>
            </Grid>
        </DataTemplate>

        <Style TargetType="{x:Type TextBlock}" x:Key="Header">
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Color="#EEE" Offset="0"/>
                        <GradientStop Color="#AAA" Offset="1"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="Padding" Value="10,0,0,0"/>
        </Style>

        <Style TargetType="{x:Type TreeView}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
        
        <Style TargetType="{x:Type ListBox}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
        </Style>

        <HierarchicalDataTemplate x:Key="SlideGroup" DataType="{x:Type slidetypes:SlideGroup}" ItemsSource="{Binding Slides}">
            <StackPanel>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <TextBlock Text="{Binding Name}" Grid.Column="1"/>
                </Grid>
            </StackPanel>

            <HierarchicalDataTemplate.ItemTemplate>
                <DataTemplate DataType="{x:Type slidetypes:Slide}">
                    <Rectangle Width="100" Height="80" Fill="White" Margin="2"/>
                </DataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>
    </fluent:MetroWindow.Resources>

    <Grid IsSharedSizeScope="true">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <fluent:Ribbon>
            <fluent:Ribbon.Menu>
                <fluent:Backstage Header="{DynamicResource menu_backstage}" x:Name="backstage">
                    <fluent:BackstageTabControl>
                        <fluent:BackstageTabItem Header="{DynamicResource new}">

                        </fluent:BackstageTabItem>
                        <fluent:BackstageTabItem Header="{DynamicResource open}">
                            <Grid Margin="20">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>

                                <StackPanel HorizontalAlignment="Left">
                                    <Button Foreground="Black" Width="100" Height="30" Content="{DynamicResource open_file}" Command="local:Backend.OpenFileCommand"/>
                                </StackPanel>
                            </Grid>
                        </fluent:BackstageTabItem>
                        <fluent:Button Header="{DynamicResource save}" IsEnabled="false"/>
                        <fluent:BackstageTabItem Header="{DynamicResource saveas}" IsEnabled="false">
        
                        </fluent:BackstageTabItem>
                    </fluent:BackstageTabControl>
                </fluent:Backstage>
            </fluent:Ribbon.Menu>

            <fluent:RibbonTabItem Header="{DynamicResource menu_start}">

            </fluent:RibbonTabItem>
        </fluent:Ribbon>


        <!--Floating panel for docking-->
        <Grid Grid.Row="1" Background="LightGray">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200" SharedSizeGroup="SidePanel1"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <TextBlock Text="{DynamicResource slides}" Style="{StaticResource Header}"/>

                <TreeView Grid.Row="1" ItemsSource="{Binding Presentation.Groups}" ItemTemplate="{StaticResource SlideGroup}" x:Name="tv_slidelist"/>
            </Grid>

            <GridSplitter HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="3" Background="DarkGray"/>
        </Grid>

        <!--Main Panel-->
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition SharedSizeGroup="SidePanel1" Width="200"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="1" DataContext="{Binding Presentation}">
                <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
                    <Grid >                        
                        <ListBox x:Name="slide" ItemsSource="{Binding Shapes}" ItemTemplate="{StaticResource ShapeTemplate}" DataContext="{Binding ElementName=tv_slidelist, Path=SelectedItem}" DataContextChanged="Grid_DataContextChanged" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden">
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <Canvas Background="White" ClipToBounds="False" Width="{Binding ElementName=window, Path=DataContext.Presentation.SlideSize.X}" Height="{Binding ElementName=window, Path=DataContext.Presentation.SlideSize.Y}">
                                    </Canvas>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                            <ListBox.ItemContainerStyle>
                                <Style>
                                    <Setter Property="Canvas.Left" Value="{Binding Position.X}"/>
                                    <Setter Property="Canvas.Top" Value="{Binding Position.Y}"/>
                                </Style>
                            </ListBox.ItemContainerStyle>
                        </ListBox>
                    </Grid>
                </ScrollViewer>
            </Grid>
        </Grid>
    </Grid>
</fluent:MetroWindow>
